home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_065 / runback / runback.asm < prev   
Assembly Source File  |  1992-05-06  |  10KB  |  408 lines

  1. * RunBack.asm
  2. *
  3. *    Written 3/11/87
  4. *
  5. * Copyright (c) 1986 by C.Heath of Microsmiths Inc.
  6. * This program may be freely distributed, but only in it's original
  7. * unmodified state.  If you wish to distribute a modified version either
  8. * commercially or otherwise, please contact:
  9. *
  10. *    Microsmiths, Inc
  11. *    PO Box 561
  12. *    Cambridge, MA 02140
  13. *    (617)354-1224
  14. *    bix: cheath  Compuserve: 74216,2117
  15. *
  16. *    This is the equivalent of Rob Peck's RunBackground program, with
  17. * an addition of a command line Stack option, "-Snnnn".  See the readme
  18. * file included with this ARC file for details.
  19. *
  20. ******    Equates and publics    ***************************************
  21.  
  22.     INCLUDE    "exec/types.i"
  23.     INCLUDE    "libraries/dos.i"
  24.     INCLUDE    "libraries/dosextens.i"
  25.  
  26. MIN_LIB        set    $1f        ; Library minimum rev level!
  27.                     ; ADOS "stack" command
  28.  
  29. MIN_STACK    set    1600        ; Minimum stack allowed by the
  30.                     ; ADOS "stack" command
  31.  
  32. *** NOTE: This was assembled with Manx V3.30E, but should be compatible
  33. ***    with MCC with minor changes.
  34.  
  35. xlib    macro    
  36.     public    _LVO\1
  37.     endm
  38.  
  39.     entry    .begin
  40.     public    .begin
  41. .begin
  42.  
  43.     xlib    OpenLibrary
  44.     xlib    CloseLibrary
  45.     xlib    FindTask
  46.  
  47.     xlib    Output
  48.     xlib    Write
  49.  
  50.     xlib    Lock
  51.     xlib    Examine
  52.     xlib    UnLock
  53.     xlib    CurrentDir
  54.     xlib    ParentDir
  55.  
  56.     xlib    Open
  57.     xlib    Close
  58.     xlib    Delay
  59.     xlib    Execute
  60.  
  61. ******    The Program        ***************************************
  62.  
  63. * Registers:
  64. *    D6 is starting SP
  65. *    D5 is execution delay
  66. *    D4 is Save SP value
  67. *        
  68. *    A5 is p->CmdLineSwished
  69. *    A4 is CLIStruct for Process Base
  70. *    A3 is p_cmdname
  71.  
  72. Start:
  73.     move.l    sp,D6            ; Save stack pointer
  74.  
  75.     move.l    A0,A2            ; Register A2 is cmdline henceforth
  76.     clr.b    0(A2,D0.w)        ; Make sure she be null terminado
  77.  
  78.     move.l    4,A6            ; ExecBase in A6 until DOSBase
  79.     suba.l    A1,A1
  80.     jsr    _LVOFindTask(A6)
  81.     move.l    D0,A4            ; Process base
  82.     move.l    pr_CLI(A4),D0
  83.      beq.s    BadExit            ; Not a CLI process. Punt
  84.     asl.l    #2,D0
  85.     move.l    D0,A4            ; A4 points at CLIStruct henceforth
  86.     move.l    cli_DefaultStack(A4),D4    ; D4 is Default Stack_a_Roo
  87.  
  88.     lea    DOSName(pc),A1        ; Open DOS.library
  89.     moveq.l    #MIN_LIB,d0
  90.     jsr    _LVOOpenLibrary(A6)
  91.     move.l    D0,A6
  92.     or.l    D0,D0
  93.      bne.s    ok_start        ; Continue if library OK,
  94.  
  95. * fall in to BadExit code if DOS library couldn't open
  96.  
  97. ************************************************************************
  98. *
  99. * BadExit is where to go if there is an error opening the DOS library
  100. *    This should only happen if things are really sick
  101. *
  102. ************************************************************************
  103. BadExit:    moveq    #20,D0
  104.         rts
  105.  
  106. ************************************************************************
  107. *
  108. * ok_start
  109. *    Proceed with normal code, check the input string.
  110. *
  111. ************************************************************************
  112. ok_start:
  113.     moveq    #0,D5            ; Default delay value
  114. *
  115. * Process the input command string
  116. *
  117. skpspc:    move.b    (A2)+,D1        ; Skip spaces 
  118.      beq.s    show_how        ; Null string - give help!
  119.     cmp.b    #$20,D1
  120.      beq.s    skpspc
  121.  
  122.     cmp.b    #$0a,D1
  123.      beq.s    show_how        ; Help! Help!!!
  124.     cmp.b    #'?',D1
  125.      beq.s    show_how        ; Also a "?" asks for help!
  126.  
  127.     cmp.b    #'-',D1
  128.      beq.s    parse_opt        ; Parse delay or stack option
  129.  
  130. * Here, A2 points at the command+1, D1 is first char
  131. do_command:
  132.  
  133. * 256 is normally max cmdline size.
  134. * But we add "run <nil:" stuff. Be safe.
  135. * CAUTION: MAKE SURE SP IS STILL LONG_WORD ALLIGNED FOR ADOS!!!!!!!!!!!!!!!!
  136.     sub    #292,sp            ; Reserve space to build cmdline!
  137.  
  138.     move.l    sp,A5            ; Space is reserved *here*
  139.     lea    Erst(pc),A0        ; Start cmd with "Run < >"
  140. 1$:    move.b    (A0)+,(A5)+
  141.      bne.s    1$
  142.     subq    #1,A5            ; Back up a char!
  143.  
  144.     move.l    A5,A3            ; Save pointer to cmd_name
  145.     move.b    #' ',D0
  146.     cmp.b    #'"',D1
  147.      bne.s    do_cmd            ; Check for Quoted string
  148.     move    D1,D0            ; Save terminator character!
  149.     addq    #1,A3            ; ADVANCE NAME PTR!!!!
  150.  
  151. do_cmd:
  152.     move.b    D1,(A5)+        ; Save the first char
  153.  
  154.     move.b    (A2),D1
  155.      beq.s    have_cmd        ; EOS - leave A2-> EOS!
  156.     cmp.b    #$0a,D1
  157.      beq.s    have_cmd        ; Ditto.
  158.  
  159.     addq    #1,A2
  160.     cmp.b    D0,D1
  161.      bne.s    do_cmd            ; Loop till terminator
  162.  
  163. * Here, the command has been copied.  Add in "<nil: .nil:"
  164. * BUT FIRST check for valid command!
  165.  
  166. have_cmd:
  167.     move.b    D0,D3            ; Save terminator damnit
  168.     clr.b    (A5)            ; Terminate the name, as command_name
  169.  
  170.     move.l    A3,D1
  171.     move.l    #ACCESS_READ,D2
  172.     jsr    _LVOLock(A6)        ; Make sure the command exists-
  173.     move.l    D0,D7            ; Or ADOS WILL GURU! YEA! ADOS!
  174.      beq.s    nofile            ; No File.  Belch!
  175.  
  176.     move.l    D0,D1
  177.     sub    #fib_SIZEOF,sp
  178.     move.l    sp,D2
  179.     jsr    _LVOExamine(A6)
  180.  
  181.     move.l    D7,D1
  182.     move.l    D0,D7
  183.     jsr    _LVOUnLock(A6)
  184.     tst    d7
  185.      beq.s    nofile            ; Can't examine. Hmm...
  186.     move.l    fib_DirEntryType(sp),D0
  187.      bge.s    nofile            ; It's a dir. Fluff, Damnit.
  188.  
  189. * Adjusting the stack is only necessary since sp is used as cmd_base
  190. * Othewise, it would be adjusted in Cleanup code.
  191.     add    #fib_SIZEOF,sp
  192.  
  193. * OK!!! It's a file, and probably even loadable!
  194. ok_cmd1:
  195.     cmp.b    #'"',D3
  196.      bne.s    Really_AddNil
  197.     move.b    D3,(A5)+
  198.  
  199. Really_AddNil:
  200.     lea    Last(pc),A0        ; Move the rest down
  201. 1$:    move.b    (A0)+,(A5)+
  202.      bne.s    1$
  203.     move.b    #' ',-1(A5)        ; OverWrite Null with Space
  204.  
  205. * Finally, copy any more of the command args
  206. finis:    move.b    (A2)+,(A5)+
  207.      bne.s    finis
  208.  
  209.     move.l    #nilnam,D1
  210.     move.l    #MODE_NEWFILE,D2
  211.     jsr    _LVOOpen(A6)
  212.  
  213.     move.l    D0,D2
  214.     move.l    D0,D3
  215.     move.l    sp,D1
  216.     jsr    _LVOExecute(A6)
  217.     tst.l    D0
  218.      beq    NoRun
  219.  
  220.     lea    OKStart(pc),A0
  221.     bsr.s    do_write
  222.  
  223.     move.l    D5,D1            ; Delay by "this" much
  224.      ble.s    goodexit
  225.  
  226.     mulu    #60,D1
  227.     jsr    _LVODelay(A6)        ; Delay 60 ticks/second
  228.  
  229.     bra    goodexit
  230.  
  231. ***************************************************************************
  232. *
  233. * parse_opt
  234. *    Parse a stack or otherwise input paramter
  235. *
  236. ***************************************************************************
  237. parse_opt:
  238.     moveq.l    #0,D1
  239.     move.b    (A2)+,D1
  240.     cmp.b    #'S',D1
  241.      beq.s    parse_stak    ; Stack-size switch
  242.     cmp.b    #'s',D1
  243.      beq.s    parse_stak    ; Um, lower case, schmoer case.
  244.  
  245.     sub.b    #'0',D1
  246.      blt.s    bad_arg        ; Must be 0..9 delay switch,
  247.     cmp.b    #9,D1
  248.      bgt.s    bad_arg        ; If not PUNT!
  249.  
  250.     move.l    D1,D5        ; Save Delay option
  251.     move.b    (A2)+,D1
  252.     cmp.b    #' ',D1        ; Must be followed by a SPACE
  253.      beq.s    skpspc        ; OK, back to main cmdline loop
  254.     bra.s    bad_arg
  255.  
  256. parse_stak:
  257. *
  258. * Here, loop to get input for new stack
  259. * Loop getting Ascii digits
  260. *
  261.     moveq.l    #0,D0            ; New Stack Value built into D0
  262. 1$:    moveq.l    #0,D1
  263.     move.b    (A2)+,D1
  264.     cmp.b    #' ',D1
  265.      beq.s    do_stak            ; Terminate number on SPACE
  266.  
  267.     sub.b    #'0',D1
  268.      blt.s    bad_arg            ; Test for valid digits
  269.     cmp.b    #9,D1
  270.      bgt.s    bad_arg
  271.  
  272.     add.l    D0,D0
  273.     move.l    D0,D2            ; Multiply prior value by 10
  274.     asl.l    #2,D2            ; Required to allow long_word value
  275.     add.l    D2,D0
  276.  
  277.     add.l    D1,D0            ; Add in new digit
  278.     bra.s    1$            ; Loop on digits
  279.  
  280. do_stak: cmp.l    #MIN_STACK,D0
  281.      blt.s    bad_arg            ; Match "stack" command
  282.  
  283.     lsr.l    #2,D0            ; Convert to LWords
  284.     move.l    D0,cli_DefaultStack(A4)
  285.     bra    skpspc
  286.  
  287. ***************************************************************************
  288. *
  289. * show_how
  290. *    RBack was called with no arguement.  Just display instructions!
  291. *
  292. ***************************************************************************
  293. show_how:
  294.     lea    str_usage(pc),A0
  295.     bsr.s    do_write
  296.  
  297. goodexit:
  298.     moveq    #0,D0
  299. CleanUp:
  300.     move.l    D4,cli_DefaultStack(A4),D4    ; Restore default stack!
  301.  
  302.     move.l    D0,D2            ; Save return value
  303.     move.l    A6,A1
  304.     move.l    4,A6            ; AbsExecBase
  305.     jsr    _LVOCloseLibrary(A6)
  306.  
  307.     move.l    D6,SP            ; Restore initial SP
  308.     move.l    D2,D0            ; Restore return value
  309.     rts                ; and exit()
  310.  
  311. bad_arg:
  312.     lea    BadArg(pc),A0
  313.     bra.s    err_msg
  314.  
  315.  
  316. ***************************************************************************
  317. *
  318. * NoRun
  319. *    Can't find c:Run, probably.  Close the nil: handle
  320. *
  321. ***************************************************************************
  322. NoRun:
  323.     move.l    D2,D1
  324.     jsr    _LVOClose(A6)        ; Close the nil: file handle
  325.  
  326.     lea    CantStart(pc),A0
  327.  
  328. ***************************************************************************
  329. *
  330. * err_msg
  331. *    Merge point for some error messages.  Exits through cleanup
  332. *
  333. ***************************************************************************
  334. err_msg:
  335.     bsr.s    do_write
  336.  
  337.     moveq    #10,D0            ; Set to exit(10)
  338.     bra.s    CleanUp
  339.  
  340. ***************************************************************************
  341. *
  342. * do_write
  343. *    Simple write string.
  344. *
  345. *    Assumes A6 = DOSBase
  346. *    Null terminated string is @A0
  347. *    Also assumes a reasonable CLI environment with valid COS
  348. *
  349. *    Zaps D0..D3/A0/A1
  350. *
  351. ***************************************************************************
  352. do_write:
  353.     move.l    A0,D2
  354.     moveq    #-1,D3
  355. dwl1:    addq.l    #1,D3
  356.     tst.b    (A0)+
  357.      bne.s    dwl1
  358.  
  359. do_writex:            ; BCPL style entry with D2/D3 preset...
  360.     jsr    _LVOOutput(A6)
  361.     move.l    D0,D1
  362.     jmp    _LVOWrite(A6)
  363.  
  364. ***************************************************************************
  365. *
  366. * nofile
  367. *    Here, the command can't be found!
  368. *
  369. ***************************************************************************
  370. nofile:
  371.     lea    CantFind(pc),A0
  372.     bsr    do_write
  373.  
  374.     move.l    A3,A0
  375.     bsr    do_write
  376.  
  377.     lea    LFStr(pc),A0
  378.     bra    err_msg
  379.  
  380. ***************************************************************************
  381. *
  382. * Following is just constant data used by the program
  383. *
  384. ***************************************************************************
  385.  
  386. DOSName:    dc.b    'dos.library',0
  387.  
  388. BadArg:
  389.  dc.b 'Invalid parameter for RunBack!',$0a,$0a
  390. str_usage:
  391.  dc.b 'RunBack © 1987 by Microsmiths, Inc',$0a
  392.  dc.b 'Usage: RunBack [-<loaddelay>] [-Snnnn] <name> [<parm(s)>]',$0a
  393.  dc.b '     where optional loaddelay is 0-9 seconds,',$0a
  394.  dc.b '     and Snnnn is an optional Stack size to set',$0a,0
  395.  
  396. Erst:        dc.b    'RUN >NIL: <NIL: ',0
  397. Last        dc.b    ' <NIL: >
  398. nilnam:        dc.b    'NIL:',0
  399.  
  400. CantStart:    dc.b    "RunBack: Error starting background task!',$0a
  401.         dc.b    "You must have the program 'Run' in your C: directory",$0a,0
  402.  
  403. CantFind:    dc.b    "Can't find ",0
  404.  
  405. OKStart:    dc.b    'Started background task'
  406. LFStr:        dc.b    $0a,0
  407.  
  408.     END